package com.example.controller;

import com.example.common.PageResult;
import com.example.common.Result;
import com.example.pojo.dto.GoodsOrdersAddDto;
import com.example.pojo.dto.GoodsOrdersQueryDto;
import com.example.pojo.vo.GoodsOrdersQueryVo;
import com.example.service.GoodsOrdersService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * 宠物用品订单 controller 层
 */
@RestController
@RequestMapping("/goodsOrders")
public class GoodsOrdersController {

    @Resource
    private GoodsOrdersService goodsOrdersService;

    @PostMapping("/add")
    public Result add(@RequestBody List<GoodsOrdersAddDto> dtoList) {
        this.goodsOrdersService.add(dtoList);
        return Result.success();
    }

    @GetMapping("/pageQuery")
    public Result pageQuery(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            GoodsOrdersQueryDto dto
    ) {
        PageResult<GoodsOrdersQueryVo> pageResult = this.goodsOrdersService.pageQuery(pageNum, pageSize, dto);
        return Result.success(pageResult);
    }

    @PutMapping("/cancel")
    public Result cancel(@RequestParam Integer id) {
        this.goodsOrdersService.cancel(id);
        return Result.success();
    }

    @PutMapping("/pay")
    public Result pay(@RequestParam Integer id) {
        this.goodsOrdersService.pay(id);
        return Result.success();
    }

    @PutMapping("/send")
    public Result send(@RequestParam Integer id) {
        this.goodsOrdersService.send(id);
        return Result.success();
    }

    @PutMapping("/sign")
    public Result sign(@RequestParam Integer id) {
        this.goodsOrdersService.sign(id);
        return Result.success();
    }
}
